home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / psend.arc / PTEST.ASM < prev    next >
Assembly Source File  |  1987-09-29  |  11KB  |  286 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                       ;;
  3. ;;   PTEST.ASM    Last modified: 09/29/87    R. Trevithick    MASM 4.0   ;;
  4. ;;-----------------------------------------------------------------------;;
  5. ;;    Tests and displays the printer control code files used by PSEND.   ;;
  6. ;;                                                                       ;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9.  
  10. CR      equ     0dh                             ; carriage return
  11. LF      equ     0ah                             ; line feed
  12. BS      equ     08h                             ; backspace
  13. TAB     equ     09h                             ; tab character
  14. BELL    equ     07h                             ; sound the horn
  15. BSIZE   equ     07fffh                          ; 32K buffer should do it!
  16.  
  17.  
  18. PRT     SEGMENT PARA PUBLIC 'CODE'              ; some info for the assembler
  19.         ASSUME  CS:PRT, DS:PRT
  20.         ORG     0100h
  21.  
  22.  
  23. start:  cmp     byte ptr ds:[80h], 1            ; any parameters?
  24.         jg      parm
  25.         mov     dx, offset usage                ; no, usage message
  26.         call    msg                             ; ...and abort
  27.         inc     errors
  28.         jmp     exit
  29.  
  30. parm:   mov     si, 82h
  31. parm2:  cmp     byte ptr ds:[si], 0dh
  32.         jne     parm3
  33.         mov     byte ptr ds:[si], 0             ; insert zero byte for DOS
  34.         jmp     short open
  35. parm3:  inc     si
  36.         jmp     short parm2
  37.  
  38. open:   mov     dx, 82h                         ; point to filespec in PSP
  39.         mov     ax, 3d00h                       ; try to open for read-only
  40.         int     21h
  41.         jnc     read
  42.         mov     dx, offset op_err
  43.         call    msg
  44.         inc     errors
  45.         jmp     exit
  46.  
  47. read:   mov     bx, ax                          ; get handle into bx
  48.         mov     dx, offset ds:buffer            ; point to the buffer
  49.         mov     ah, 03fh                        ; read service
  50.         mov     cx, BSIZE                       ; size of read buffer
  51.         int     21h
  52.         jnc     read2
  53.         mov     dx, offset rd_err
  54.         call    msg
  55.         inc     errors
  56.         jmp     exit
  57.  
  58. read2:  cmp     ax, 0                           ; special case, 0 byte file
  59.         jne     read3
  60.         mov     dx, offset no_data
  61.         call    msg
  62.         inc     errors
  63.         jmp     exit
  64.  
  65. read3:  cmp     ax, BSIZE                       ; see if too large a file
  66.         jb      disp
  67.         mov     dx, offset too_big
  68.         call    msg
  69.         inc     errors
  70.         jmp     exit
  71.  
  72. ;
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  74. ; here's where the work get's done
  75. ;
  76. ; bh = parser flag, bl = strlen
  77. ;
  78.  
  79. disp:   push    ax                              ; save return value
  80.         mov     dx, offset codes                ; show 'Codes:' message
  81.         call    msg
  82.         pop     cx                              ; bytes read into loop counter
  83.  
  84.         call    pr_chk                          ; check the printer
  85.  
  86.         xor     bx, bx                          ; zero out our flags
  87.         mov     si, offset buffer               ; pointer into file buffer
  88.         mov     di, offset pr_buff              ; pointer into printer string
  89.  
  90. disp2:  mov     dx, offset bad_len              ; most likely error here
  91.         mov     al, byte ptr ds:[si]            ; get a character
  92.         cmp     al, '<'                         ; is it a start char?
  93.         jne     disp3                           ; no, process it further
  94.         inc     bh                              ; yes, set flag
  95.         inc     count                           ;  track number found
  96.         mov     al, 20h                         ;   make it a space
  97.         jmp     short disp5                     ;    and display it
  98.  
  99. disp3:  cmp     bh, 0                           ; is flag set?
  100.         je      disp6                           ; no, skip this one
  101.         cmp     al, '>'                         ; is it an end char?
  102.         jne     disp4                           ; no, see if length ok
  103.  
  104.         xor     bh, bh                          ; yes, turn off parser flag
  105.         cmp     bl, 0                           ; any valid chars?
  106.         je      abort                           ; no, flag it as error
  107.  
  108.         call    print                           ; try to send it to printer
  109.  
  110.         xor     bl, bl                          ;  reset length counter
  111.         mov     di, offset pr_buff              ;   reset pointer to output
  112.         jmp     short disp6                     ;    and back for more
  113.  
  114. disp4:  inc     bl                              ; bump up length counter
  115.         cmp     bl, 3                           ; max length allowed
  116.         ja      abort                           ; no good, skip numeric test
  117.  
  118.         mov     dx, offset bad_val              ; ready for value error
  119.         cmp     al, '0'                         ; check for valid numeric
  120.         jb      abort
  121.         cmp     al, '9'
  122.         ja      abort                           ; not numeric, abort
  123.  
  124.         jmp     short disp5                     ; ok, let this one through
  125.  
  126. abort:  xor     bh, bh                          ; bad code - reset system
  127.         cmp     bl, 1                           ; have we shown any yet?
  128.         ja      abort2                          ; yes, show the dash
  129.         inc     dx                              ; no, display error alone
  130.  
  131. abort2: xor     bl, bl
  132.         inc     errors                          ; bump up our error count
  133.         call    msg                             ; dx already set
  134.  
  135.         jmp     short disp6                     ; back for more
  136.  
  137. disp5:  mov     dl, al                          ; display this byte
  138.         mov     ah, 02h                         ;  using DOS service
  139.         int     21h
  140.  
  141.  
  142. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  143. ; build up printer output string
  144. ;
  145.         cmp     dl, 20h                         ; skip the 1st one (space)
  146.         je      disp6
  147.  
  148.         sub     dl, '0'                         ; convert to binary
  149.         mov     byte ptr ds:[di], dl            ; stick it in print buffer
  150.         inc     di                              ; bump up print buffer pointer
  151.  
  152. disp6:  inc     si                              ; point to next byte
  153.         dec     cx                              ; unless end of buffer
  154.         jz      done                            ; end, done
  155.  
  156.         jmp     disp2                           ; more, go get next byte
  157.  
  158.  
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  160. done:   cmp     count, 0                        ; any codes found?
  161.         ja      errmsg                          ; yes
  162.         mov     dx, offset nothing              ; no, mention the fact
  163.         call    msg
  164.         jmp     short exit                      ;  and skip other messages
  165.  
  166. errmsg: cmp     errors, 0                       ; any errors?
  167.         je      final                           ; no
  168.         mov     dx, offset bomb                 ; yes, error message
  169.         call    msg
  170.  
  171. final:  cmp     pr_flag, 0                      ; printer message needed?
  172.         ja      exit                            ; no, just exit
  173.         mov     dx, offset pr_msg               ; yes, send it
  174.         call    msg                             ; and fall through to exit
  175.  
  176. ;
  177. ;----------------------------------------------------------------------------
  178. ; misc routines coded below
  179.  
  180.  
  181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  182. ; general exit routine
  183. ;
  184. exit:   mov     al, errors                      ; set errorlevel == errors
  185.         mov     ah, 4ch
  186.         int     21h
  187.  
  188.  
  189. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  190. ; send a message to console
  191. ;
  192. msg:    mov     ah, 09h                         ; display a message
  193.         int     21h
  194.         ret
  195.  
  196.  
  197. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  198. ; send codes to printer
  199. ;
  200. print:  push    dx
  201.         push    cx
  202.  
  203.         xor     dx, dx                          ; zero out output byte
  204.         dec     di                              ; last digit found
  205.  
  206.         mov     dl, byte ptr ds:[di]            ; get ones digit
  207.         dec     di
  208.         dec     bl
  209.         jz      pr_out
  210.  
  211.         mov     al, byte ptr ds:[di]            ; this is tens digit
  212.         mov     cl, 10
  213.         mul     cl
  214.         add     dl, al
  215.         dec     di                              ; back up again
  216.         dec     bl
  217.         jz      pr_out
  218.  
  219.         mov     al, byte ptr ds:[di]            ; this is hundreds digit
  220.         mov     cl, 100
  221.         mul     cl
  222.         jc      pr_val                          ; carry flag, error
  223.         add     dl, al
  224.         jc      pr_val                          ; check again after add
  225.  
  226. pr_out: cmp     pr_flag, 0                      ; is printer on-line?
  227.         jz      prexit                          ; no, just return
  228.         mov     ah, 05h                         ; get ready to send
  229.         int     21h                             ; send out the value
  230.         jmp     short prexit                    ; and skip error routine
  231.  
  232. pr_val: mov     dx, offset bad_val              ; show the error with dash
  233.         call    msg
  234.         inc     errors                          ; bump up our error counter
  235.  
  236. prexit: pop     cx
  237.         pop     dx
  238.         ret
  239.  
  240.  
  241. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  242. ; see if printer is ready
  243. ;
  244. pr_chk: xor     dx, dx                          ; default printer
  245.         mov     ah, 2                           ; printer status function
  246.         int     17h                             ; of bios printer services
  247.         cmp     ah, 10010000b                   ; printer on-line?
  248.         jne     ck_ret
  249.         mov     pr_flag, 1                      ; ok to print, flag it
  250. ck_ret: ret
  251.  
  252.  
  253. ;
  254. ;----------------------------------------------------------------------------
  255. ; data storage area
  256.  
  257.  
  258. usage   db      CR, LF, 'Test printer control code files ', 0feh, ' '
  259.         db      'R.Trevithick 09/29/87', CR, LF, LF, '    '
  260.         db      'PTEST [d:][path]filename.ext', CR, LF, '$'
  261.  
  262. op_err  db      TAB, 'cannot open file', BELL, '$'
  263. rd_err  db      TAB, 'read error',       BELL, '$'
  264. too_big db      TAB, 'file too large',   BELL, '$'
  265. no_data db      TAB, 'file is empty',    BELL, '$'
  266.  
  267. codes   db      CR, LF, 'Codes:$'
  268.  
  269. bad_len db      '-<L>$'
  270. bad_val db      '-<V>$'
  271.  
  272. nothing db      ' none found', CR, LF, '$'
  273. bomb    db      CR, LF, TAB, 'errors found in codes!', BELL, '$'
  274. pr_msg  db      CR, LF, TAB, 'printer not accepting characters$'
  275.  
  276. pr_flag db      0
  277. errors  db      0
  278. count   db      0
  279.  
  280. pr_buff db      3 dup (?)
  281. buffer  db      BSIZE dup (?)
  282.  
  283. PRT     ENDS
  284.         END     START
  285.  
  286.